package com.cupdata.marathon.utils;

public class StringUtils {

    public static final String EMPTY_STRING = "";

    public static String leftShift(String in,int len){
        if(len>=in.length()){
            return null;
        }
        StringBuilder stringBuilder=new StringBuilder(in);
        stringBuilder.delete(0,len);
        return stringBuilder.toString();
    }

    public static String cutLastString(String in,int len){
        if(len>=in.length()){
            return null;
        }
        int length=in.length();
        StringBuilder stringBuilder=new StringBuilder(in);
        stringBuilder.delete(length-len,length);
        return stringBuilder.toString();
    }

    public static String rightShift(String in,String insertStr,int len){
        StringBuilder inBuilder=new StringBuilder(in);
        StringBuilder insertStrBuilder=new StringBuilder(insertStr);
        if(insertStr.length()>len){
            insertStrBuilder.delete(len,insertStr.length());
        }else if(insertStr.length()<len){
            for(int i=0;i<len-insertStr.length();i++){
                insertStrBuilder.append("0");
            }
        }
        inBuilder.insert(0,insertStrBuilder);
        return inBuilder.toString();
    }

    public static String rightReplace(String in,String replaceStr){
        StringBuilder inBuilder=new StringBuilder(in);
        int length=in.length();
        if(replaceStr.length()>in.length()){
            return null;
        }
        inBuilder.replace(length-replaceStr.length(),length,replaceStr);
        return inBuilder.toString();
    }

    public static String rightAppender(String in,String insertStr){
        StringBuilder inBuilder=new StringBuilder(in);
        inBuilder.append(insertStr);
        return inBuilder.toString();
    }

    public static boolean isBlank(String str) {
        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((!Character.isWhitespace(str.charAt(i)))) {
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args){
        String in="12345678";
        /* String out=leftShift(in,4);*/
        /* String out=rightShift(in,"abc",3);*/
        String out=rightReplace(in,"00");
    }
}
